#ifndef __PHLOGGER_APPLE_H__
#define __PHLOGGER_APPLE_H__

#pragma warning(disable: 4996)
#pragma warning(disable: 4995)

#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <string>
#include <stdarg.h>

#include "flogger.h"


#ifndef _vscprintf
	#define _vscprintf(a,b) 10240
#endif //_vscprintf

#ifndef DISENABLE_LOGGER
	#ifdef _WRITE_LOG_TO_CONSOLE
		inline void OpenLogger(const char*){}
        inline void SetMaxSize(unsigned long) {}
		static void WriteLog(int evt,const char* str,...)
		{
            if(!(evt & logConfigs)) return ;
            char stime[32] = "";
            time_t now = time(NULL);
            struct tm *tm = localtime(&(now));
            if (tm) strftime(stime, sizeof(stime),"%Y-%m-%d %H:%M:%S\t", tm);
            
			char *fmtstr = NULL;
			int len = 0;
			va_list   varg;   
			va_start(varg,   str);
			len = _vscprintf( str, varg );
			fmtstr = new char[len+1];
			fmtstr[len] = 0;
			vsnprintf(fmtstr,len, str,   varg);   
			va_end(varg); 
			printf("%s\t%s\t%s\n",stime, string_event(evt),fmtstr);
			delete [] fmtstr;
		}
	#else //_WRITE_LOG_TO_CONSOLE
    #ifdef WRITE_SYS_LOG
        class AppleLogger
        {
        public:
            typedef
            enum _logstyle
            {
                with_fixedsize = 0, /*!< Default style */
                with_hour = 1, /*!< Write log file name with hour format */
            } logstyle;
            
            static AppleLogger &GetInitance(){return s_logger; }
            AppleLogger():m_flag(0)
            {
            }
            void Path(const char *path)
            {
                
            }
            void Flag(int flag)
            {
                m_flag = flag;
            }
            void MaxSize(int size)
            {
                
            }
            ~AppleLogger();
            void open(const char *name,logstyle style=with_fixedsize);
            void write_log(int evt,const char* str,...);
        private:
            static AppleLogger s_logger;
            //aslclient log_client;
            std::string m_path;
            std::string m_name;
            int m_flag;
            
        };
        
        #define SetLogPath AppleLogger::GetInitance().Path
        #define OpenLogger AppleLogger::GetInitance().open
        #define WriteLog AppleLogger::GetInitance().write_log
        #define SetMaxSize AppleLogger::GetInitance().MaxSize
        #define SetLogFlag  AppleLogger::GetInitance().Flag
    #else
        #define SetLogPath flogger::GetInitance().Path
		#define OpenLogger flogger::GetInitance().open
		#define WriteLog flogger::GetInitance().write_log
        #define SetMaxSize flogger::GetInitance().MaxSize
        #define SetLogFlag  flogger::GetInitance().Flag
    #endif
	#endif //_WRITE_LOG_TO_CONSOLE

	inline void EnableLogger(bool ){}
	inline void SetLoggerPipe(const char*){}
	inline void CloseLoggerPipe(){}
#else //DISENABLE_LOGGER
	inline void OpenLogger(const char*){}
	inline void EnableLogger(bool){}
	inline void WriteLog(...){}
	inline void SetLoggerPipe(const char*){}
	inline void CloseLoggerPipe(){}
    inline void SetMaxSize(unsigned long) {}
#endif //DISENABLE_LOGGER

#endif //__PHLOGGER_H__

